/* Copyright 2001,2002,2003 NAH6 BV
 * All Rights Reserved
 *
 *  $Header: /var/lib/cvs/secphone/ui/database/SysCallLog.cpp,v 1.5 2003/11/21 12:39:24 itsme Exp $
 *
 *
 * this file handles the microsoft phone calllog database
 *
 * the intention is to remove the incoming datacalls from the
 * analog phone app calllog.
 *
 * not yet used
 *
 */
#include "SysCallLog.h"

// SysCallLog can only be searched by DBSYSCALLLOG_START_FIELD in descending order.

WCHAR *SysCallLog::DatabaseName()
{
    return L"clog.db";
}

SysCallLog::SysCallLog()
{
}

SysCallLog::~SysCallLog()
{
}

void SysCallLog::Open()
{
    m_db.Open(DatabaseName());
}

void SysCallLog::AddEntry(const SysCallLogEntry &entry)
{
    CeRecord rec(6);
    rec.AddString(DBSYSCALLLOG_NAME_FIELD, entry.name);
    rec.AddString(DBSYSCALLLOG_NUMBER_FIELD, entry.number);
    rec.AddString(DBSYSCALLLOG_NUMBERTYPE_FIELD, entry.numberType);
    rec.AddTimestamp(DBSYSCALLLOG_START_FIELD, &entry.startTime);
    rec.AddTimestamp(DBSYSCALLLOG_END_FIELD, &entry.endTime);
    rec.AddUInt32(DBSYSCALLLOG_CALLTYPE_FIELD, entry.callType);
    m_db.CommitRecord(rec);
}

// this function deletes the most recent call from number from the calllog.
void SysCallLog::RemoveEntry(char *number)
{
    WCHAR *buf= new TCHAR[strlen(number)+1];
    wsprintf(buf, L"%hs", number);

    CEOID recid;
    DWORD dwFieldId;
    if (m_db.LinearSearch(DBSYSCALLLOG_NUMBER_FIELD, &dwFieldId, &recid, (DWORD)buf))
        m_db.DeleteRecord(recid);

    delete buf;
}

